var $ = require("jquery");
var receiveDetailTpl = require("../../../tpl/receiveDetail.tpl");
var tplUtil = require("../../util/templateUtil.js");
var util = require("../../util/util.js");
module.exports = {
    tpl: receiveDetailTpl,
    init: function (jDom, data)
    {
        data.detail = JSON.parse(data.detail);
        var latestTime = util.getDays(util.hackDate(data.latestTime));
        var newDetail = [];
        data.detail.map(function (item) {
            var date = util.hackDate(item.time);
            var object = {
                date: util.format(date, 'yyyy.MM.dd'),
                time: util.format(date, 'hh:mm'),
                content: item.context
            };
            var index = latestTime - util.getDays(date);
            if (!newDetail[index]) {
                newDetail[index] = [];
            }
            newDetail[index].push(object);
        });
        data.detail = newDetail;
        data.corpItem = util.getCorpItem(data.com);
        jDom.html(this.render(data));
    },
    render: function (data)
    {
        return tplUtil.template(this.tpl, {
            detail: data
        });
    }
};